package br.ufmg.ubicomp.droidguide.service;

import java.util.Collection;
import java.util.HashMap;

import br.ufmg.ubicomp.droidguide.profile.DroidGuideUser;

public class LoginService extends DGServerService{

	public static final String PW = "pw";
	public static final String USERNAME = "username";
	private Collection<DroidGuideUser> users;
	public LoginService() {
		super();
		params = new HashMap<String, Object>();
	}
	
	public LoginService(Collection<DroidGuideUser> users) {
		this();
		this.users = users;
	}

	public Collection<DroidGuideUser> getUsers() {
		return users;
	}

	@Override
	public boolean execute() {
		
		String username = (String) getParameter(USERNAME);
		String password = (String) getParameter(PW);
		
		boolean success = false;
		
		for (DroidGuideUser user: users)
		{
			if (user.getLogin().equals(username) &&
					user.getPw().equals(password))
			{
				success = true;
			}
		}
		return success;
	}	
	
}

